package jlib.component.button
{
	
	import flash.display.InteractiveObject;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import jlib.component.button.IButton;
	import jlib.component.button.IButtonStrategy;
	
	internal final class ToggleStrategy implements IButtonStrategy
	{
		private var m_bSelected:Boolean;
		private var m_button:IButton;
		public function ToggleStrategy(button:IButton)
		{
			m_button = button;
		}
		
		public function click(e:Event=null): void
		{
			if(m_bSelected) up(e);
			else down(e);
			m_bSelected = !m_bSelected;
			if(m_button.hasState(ButtonState.ROLLOVER)) rollOver(e);
		}
		
		public function down(e:Event=null):void
		{
			m_button.view(ButtonState.DOWN);
		}
		
		public function up(e:Event=null):void
		{
			m_button.view(ButtonState.UP);
		}
		
		public function rollOver(e:Event=null):void
		{
			if(e) m_button.view(ButtonState.ROLLOVER);
		}
		
		public function rollOut(e:Event=null):void
		{
			if(m_bSelected) down();
			else up();
		}
		
		public function outside(e:Event=null):void
		{
			if(m_bSelected) down();
			else up();
		}
		
		public function isSelected(): Boolean {
			return m_bSelected;
		}
	}//c
}